 % Copyright (C) 2012 	Paul Bovbel, paul@bovbel.com
 % 						Richard Abrich, abrichr@gmail.com
 %
 % This file is part our empirical study of boosting algorithms (http://code.google.com/p/boosting-study/)
 % 
 % This is free software; you can redistribute it and/or modify
 % it under the terms of the GNU General Public License as published by
 % the Free Software Foundation; either version 3 of the License, or
 % (at your option) any later version.
 % 
 % This source code is distributed in the hope that it will be useful,
 % but WITHOUT ANY WARRANTY; without even the implied warranty of
 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 % GNU General Public License for more details.
 % 
 % You should have received a copy of the GNU General Public License
 % along with this source code. If not, see http://www.gnu.org/licenses/

function [ weak_classifier, D ] = adaboost( parameters, match, D, i, margin)
%ADABOOST updates error and weighting of weak classifier, as well as data
%probability for next round of training
%   weak_classifier - structure
%   mismatch - table of mismatched values from the weak classifier alg

    weak_classifier.N = i;

    %calculate weak classifier parameters
    weak_classifier.parameters = parameters;
    edge = sum(D .* (match < 0));
    weak_classifier.mismatch_count = sum(match < 0);
    weak_classifier.weight = 0.5 * log( (1-edge) / edge) - 0.5 * log ( ( 1+margin)/(1-margin) );
    
    D = D .* exp(-match .* weak_classifier.weight);
    D = D/sum(D);
    
end

